package com.haixiaoke.saas.manage.user.controller;


import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.system.BaseController;
import com.haixiaoke.saas.user.domain.User;
import com.haixiaoke.saas.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户Controller
 *
 * @author xiaolong
 * @date 2025-04-01
 */
@RestController
@RequestMapping("/manage/user/user")
public class ManageUserController extends BaseController {

    @Autowired
    private IUserService userService;

    /**
     * 查询用户信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(User user) {
        startPage();
        List<User> list = userService.selectUserList(user);
        return getDataTable(list);
    }

    /**
     * 编辑用户
     */
    @PutMapping
    public AjaxResult edit(@RequestBody User user) {
        user.setUpdateBy(getLoginUser().getUsername());
        return toAjax(userService.editUser(user));
    }

    /**
     * 禁用/启用用户
     */
    @PutMapping("/accountStatus/{userId}")
    public AjaxResult updateUserAccountStatus(@PathVariable("userId") Long userId) {
        return toAjax(userService.updateUserAccountStatus(userId, getLoginUser().getUsername()));
    }

    /**
     * 注销用户
     */
    @PutMapping("/logoutUser/{userId}")
    public AjaxResult logoutUser(@PathVariable("userId") Long userId) {
        return toAjax(userService.logoutUser(userId, getLoginUser().getUsername()));
    }

    /**
     * 首页
     */
    @GetMapping("/homePage")
    public AjaxResult homePage() {
        return success(userService.homePage());
    }
}
